import _ from 'lodash';

let term = {
  moreOperate: {
    modeSelect: {
      value: '模式选择',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.moreOperate.modeSelect',
    },
    allCondition: {
      value: '全部条件',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.moreOperate.allCondition',
    },
    enableAllCondition: {
      value: '启用',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.moreOperate.enableAllCondition',
    },
    disableAllCondition: {
      value: '禁用',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.moreOperate.disableAllCondition',
    },
    deleteAllCondition: {
      value: '删除',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.moreOperate.deleteallCondition',
    },
  },
  operate: {
    equal: {
      value: '等于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.equal',
    },
    equalSign: {
      value: '=',
      ReferenceExpr: '',
    },
    notEqual: {
      value: '不等于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.notEqual',
    },
    notEqualSign: {
      value: '≠',
      ReferenceExpr: '',
    },
    contains: {
      value: '包含',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.contain',
    },
    containsSign: {
      value: '包含',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.contain',
    },
    notcontains: {
      value: '不包含',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.notcontains',
    },
    notcontainsSign: {
      value: '不包含',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.notcontainsSign',
    },
    startwith: {
      value: '开始于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.startwith',
    },
    startwithSign: {
      value: '开始于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.startwithSign',
    },
    endwith: {
      value: '结束于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.endwith',
    },
    endwithSign: {
      value: '结束于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.endwithSign',
    },
    isblank: {
      value: '为空',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.isblank',
    },
    isblankSign: {
      value: '为空',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.isblankSign',
    },
    isnotblank: {
      value: '不为空',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.isnotblank',
    },
    isnotblankSign: {
      value: '不为空',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.isnotblankSign',
    },
    in: {
      value: '隶属',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.in',
    },
    inSign: {
      value: '隶属',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.inSign',
    },
    notin: {
      value: '非隶属',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.notin',
    },
    notinSign: {
      value: '非隶属',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.notinSign',
    },
    lessThan: {
      value: '小于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.lessThan',
    },
    lessThanSign: {
      value: '<',
      ReferenceExpr: '',
    },
    moreThan: {
      value: '大于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.moreThan',
    },
    moreThanSign: {
      value: '>',
      ReferenceExpr: '',
    },
    lessThanEqual: {
      value: '小于等于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.lessThanEqual',
    },
    lessThanEqualSign: {
      value: '≤',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.operate.lessThanEqualSign',
    },
    MoreThanEqual: {
      value: '大于等于',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.MoreThanEqual',
    },
    MoreThanEqualSign: {
      value: '≥',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.operate.MoreThanEqualSign',
    },
    between: {
      value: '之间',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.between',
    },
    betweenSign: {
      value: '之间',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.operate.betweenSign',
    },
  },
  Relation: {
    while: {
      value: '当',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Relation.while',
    }, //
    and: {
      value: '且',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Relation.and',
    }, //且
    or: {
      value: '或',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Relation.or',
    }, //或
    and1: {
      value: '并且',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Relation.and1',
    }, //并且
    or1: {
      value: '或者',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Relation.or1',
    },
  },
  Notify: {
    warningTitle: {
      value: '警告',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Notify.warning_title',
    }, //
    warningText_checkTypeNumber: {
      value: '请输入数字类型条件值',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.Notify.warningText_checkTypeNumber',
    },
    warningText_noField: {
      value: '未获取到筛选字段设置信息，请联系管理员',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.Notify.warningText_noField',
    },
    warningText_none: {
      value: '请输入要查询的',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Notify.warningText_none',
    },
    warningText_invalid: {
      value: '条件值 不合理，请重新输入',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.Notify.warningText_invalid',
    },
    warningText_ismust: {
      value: '条件 必须存在，请设置',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.Notify.warningText_ismust',
    }, //！
    noFilter: {
      value: '未预置查询条件，请联系管理员',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Notify.noFilter',
    },
    delAll: {
      value: '确认全部删除?',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Notify.delAll',
    },
    clearAll: {
      value: '确定要清空全部查询条件吗?', // 确认全部清除
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Notify.clearAll',
    },
    confirmText: {
      value: '确认信息',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Notify.confirmText',
    },
    confirm: {
      value: '确认',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Notify.confirm',
    },
    cancel: {
      value: '取消',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Notify.cancel',
    },
    shiftCheckText: {
      value: '当前存在条件组,无法切换为简单模式.',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.Notify.shiftCheckText',
    },
    shiftCheckClassicText: {
      value: '当前存在条件组或重复条件,无法切换为经典模式.',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.Notify.shiftCheckClassicText',
    },
  },
  title: {
    switch: {
      value: '切换',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.switch',
    }, //
    to: {
      value: '为',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.to',
    }, //为
    conditionGroup: {
      value: '条件组',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.conditionGroup',
    }, //
    condition: {
      value: '条件项',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.condition',
    }, //
    deleteConditions: {
      value: '删除条件项',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.deleteConditions',
    }, //
    disable: {
      value: '禁用',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.disable',
    }, //禁用
    enable: {
      value: '启用',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.enable',
    }, //
    delete: {
      value: '删除',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.delete',
    }, //
    notMapped: {
      value: '未映射',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.notMapped',
    }, //未映射
    groupCondition: {
      value: '组',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.groupCondition',
    }, //组
    singleCondition: {
      value: '项',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.singleCondition',
    }, //项
    clearAll: {
      value: '删除全部条件',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.clearAll',
    },
    reset: {
      value: '重置为当前已保存的条件方案',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.reset',
    },
    deleteItem: {
      value: '删除条件项',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.deleteItem',
    },
    clearValue: {
      value: '清空条件值',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.title.clearValue',
    },
  },
  placeHolder: {
    placeholder_searchText: {
      value: '输入字段名称查找...',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.placeholder_searchText',
    }, //
    noData: {
      value: '无匹配字段',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.noData',
    }, //
    filterNameValue: {
      value: '查询条件 ...',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.FilterNameValue',
    }, //
    addFilterCondition: {
      value: '添加该筛选条件',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.addFilterCondition',
    }, //
    noCondition: {
      value: '当前无查询条件',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.noCondition',
    }, //
    noFilters: {
      value: '无',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.noFilters',
    }, //
    useCondition: {
      value: '应用当前查询条件',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.useCondition',
    }, //
    hideCondition: {
      value: '隐藏查询信息',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.hideCondition',
    }, //隐藏查询信息
    addItem: {
      value: '添加项',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.addItem',
    }, //添加项
    addGroup: {
      value: '添加组',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.addGroup',
    }, //添加组
    clickChange: {
      value: '点击下拉切换',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.clickChange',
    },
    deleteAllItem: {
      value: '删除全部条件',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.deleteAllItem',
    },
    closeAllItem: {
      value: '禁用全部条件',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.closeAllItem',
    },
    openAllItem: {
      value: '启用全部条件',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.openAllItem',
    },
    shiftEasyModel: {
      value: '切为简单模式',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.shiftEasyModel',
    },
    shiftCompModel: {
      value: '切为复杂模式',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.shiftCompModel',
    },
    shiftClassicModel: {
      value: '切为经典模式',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.shiftClassicModel',
    },
    currFilters: {
      value: '当前条件',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.currFilters',
    },
    clearAll: {
      value: '全清',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.clearAll',
    },
    unselectAll: {
      value: '取消全选',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.unselectAll',
    },
    showFilters: {
      value: '展开',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.showFilters',
    },
    hideFilters: {
      value: '收起',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.hideFilters',
    },
    query: {
      value: '查询',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.query',
    },
    reset: {
      value: '重置',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.reset',
    },
    clear: {
      value: '清空',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.clear',
    },
    moreSet: {
      value: '更多条件设置',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.moreSet',
    },
    filterSet: {
      value: '查询条件设置',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.filterSet',
    },
    selectAll: {
      value: '全选',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.selectAll',
    },
    cancel: {
      value: '取消',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.cancel',
    },
    sure: {
      value: '确定',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.sure',
    },
    letinput: {
      value: '请输入',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.letinput',
    },
    letselect: {
      value: '请选择',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.letselect',
    },
    layoutUpdate: {
      value: '条件布局调整',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.placeHolder.layoutUpdate',
    },
    layout2: {
      value: '一行两列条件',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.layout2',
    },
    layout3: {
      value: '一行三列条件',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.layout3',
    },
    layout4: {
      value: '一行四列条件',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.layout4',
    },
    layout6: {
      value: '一行六列条件',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.layout6',
    },
    layout8: {
      value: '一行八列条件',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.placeHolder.layout8',
    },
  },
  field: {
    field: {
      value: '字段',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.field',
    }, //
    inputValue: {
      value: '输入值',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.inputValue',
    }, //
    choiseField: {
      value: '选择字段',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.choiseField',
    }, //
    addItem: {
      value: '添加项',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.addItem',
    }, //添加项
    addGroup: {
      value: '加组',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.addGroup',
    }, //加组
    add: {
      value: '加项',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.add',
    }, //加项
    complexMode: {
      value: '复杂模式',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.complexMode',
    }, //复杂模式
    simpleMode: {
      value: '简单模式',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.simpleMode',
    }, //简单模式
    classicModel: {
      value: '经典模式',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.classicModel',
    }, //简单模式
    ClickToSwitchTo: {
      value: '点击切换为',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.field.ClickToSwitchTo',
    }, //点击切换为
  },
  date: {
    last3day: {
      value: '近3天',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.last3day',
    },
    last7day: {
      value: '近7天',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.last7day',
    },
   
    today: {
      value: '今天',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.today',
    }, //今天
    yesterday: {
      value: '昨天',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.yesterday',
    }, //昨天
    thisWeek: {
      value: '本周',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.thisWeek',
    }, //本周
    lastWeek: {
      value: '上周',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.lastWeek',
    }, //
    thisMonth: {
      value: '本月',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.thisMonth',
    }, //本月
    lastMonth: {
      value: '上月',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.lastMonth',
    }, //
    thisYear: {
      value: '今年',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.thisYear',
    }, //
    lastYear: {
      value: '上年',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.lastYear',
    }, //
    thisMonday: {
      value: '本周一',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.thisMonday',
    }, //
    thisSunday: {
      value: '本周日',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.thisSunday',
    }, //本周日
    lastMonday: {
      value: '上周一',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.lastMonday',
    }, //上周一
    lastSunday: {
      value: '上周日',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.lastSunday',
    }, //上周日
    endOfThisMonth: {
      value: '本月末',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.endOfThisMonth',
    }, //
    beginningOfThisMonth: {
      value: '本月初',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.date.beginningOfThisMonth',
    }, //本月初
    endOfTLastMonth: {
      value: '上月末',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.endOfLastMonth',
    }, //
    beginningOfLastMonth: {
      value: '上月初',
      ReferenceExpr:
        'Schema.Controls.fas_filter.Terms.date.beginningOfLastMonth',
    }, //
    earlyThisYear: {
      value: '今年初',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.earlyThisYear',
    }, //
    lastThisYear: {
      value: '上年初',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.earlyLastYear',
    }, //
    endOfThisYear: {
      value: '今年末',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.endOfThisYear',
    }, //
    endOfLastYear: {
      value: '上年末',
      ReferenceExpr: 'Schema.Controls.fas_filter.Terms.date.endOfLastYear',
    }, //
  },
};
let i18nCodes = [];
for (let i in term.date) {
  i18nCodes.push(term.date[i].ReferenceExpr);
}
//初始化执行数据
//初始化执行数据
for (let i in term) {
  for (let j in term[i]) {
    let data = term[i][j].ReferenceExpr.split('.').reduce(
      (prev, cur) => {
        try {
          if (!!prev[cur]) {
            return prev[cur];
          } else {
            return term[i][j].value;
          }
        } catch (error) {
          return term[i][j].value;
        }
      },
      (window.localMessage ? localMessage['fas_common'] : {}),
    );
    term[i][j] = data;
  }
}

export const Terms = term;

export const getTextByCode = (termList, code, locale = null) => {
  if (!(termList && termList.find)) return;
  const term = termList.find(n => n.Code === code);
  if (!term) return '';
  const { TranslateItems } = term;
  if (!TranslateItems) return '';
  if (locale) {
    const item = TranslateItems.find(n => n.Language === locale);
    return item.CustomText || item.TranslateText;
  } else {
    return TranslateItems.map(n => n.CustomText || n.TranslateText);
  }
};

export const getI18nTerms = async () => {
  if(window.readCookie&&(window.readCookie("TeldProductVersionType") == "Teld"||!readCookie("TeldProductVersionType"))){
    return []
  }
  /**
   * 数据结构
   * data: [{
   *  Code: 'Schema.Controls.fas_filter.Terms.date.today',
   *  TranslateItems: [
   *    {
   *      Language: "en-US",
   *      CustomText: '',
   *      TranslationText: 'Today',
   *    },
   *    {
   *      Language: "zh-CN",
   *      CustomText: '',
   *      TranslationText: '今天',
   *    },
   *  ]
   * }]
   */
  // const i18nCodes = ['Schema.Controls.fas_filter.Terms.date.today'];
  // TODO for fix @今天 only，maybe needs more fields in future

  // if (!i18nCodes || !Array.isArray(i18nCodes) || !i18nCodes.length) {
  //   return [];
  // }
  // i18nCodes =[]
  // for(let i in term.date){
  //   i18nCodes.push(i.ReferenceExpr)
  // }
  // i18nCodes=.map(item=>item.ReferenceExpr)

  try {
    const res = await new Promise(resolve => {
      window.getDataAsync?.(
        `${window.FrameSGHost}FASR-GetTermsBycodes&fasdevappid=${window.getFasDevAppId?.()}`,
        'post',
        {
          termCodeList: JSON.stringify(i18nCodes),
        },
        function (data) {
          resolve(data);
        },
      );
    });

    console.log('getI18nTerms', res);
    return res.data || [];
  } catch (error) {
    console.log(error);
  }
};
